package com.sskj.fca.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.fca.bean.CommonBean;
import com.sskj.fca.bean.ToRechargeBean;
import com.sskj.fca.http.HttpConfig;
import com.sskj.fca.ui.activity.RechargeActivity;

/**
 * Created by QinKang on 2019/1/2.
 */

public class RechargePresenter extends BasePresenter<RechargeActivity> {

    /**
     * 充币页面展示二维码
     */
    public void getRechargeUrl(String price) {
        httpService.getRechargeUrl(price)
                .tag(this)
                .execute(new JsonCallBack<HttpData<ToRechargeBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ToRechargeBean>> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            ToRechargeBean toRechargeBean = (ToRechargeBean) httpData.getData();
                            mView.rechargeSuccess(toRechargeBean.getUrl());
                        }
                    }
                });
    }

    /**
     * 吾彩充值
     *
     * @param price
     */
    public void getRechargeUrlTwo(String price) {
        httpService.getRechargeUrlOther(price)
                .tag(this)
                .execute(new JsonCallBack<HttpData<ToRechargeBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ToRechargeBean>> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            ToRechargeBean toRechargeBean = (ToRechargeBean) httpData.getData();
                            mView.rechargeSuccess(toRechargeBean.getUrl());
                        }
                    }
                });
    }

    /**
     * 公共数据
     */
    public void getCommonData() {
        httpService.getCommonData()
                .tag(this)
                .execute(new JsonCallBack<HttpData<CommonBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<CommonBean>> response) {
                        HttpData httpData = response.body();
//                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updataUI((CommonBean) httpData.getData());

                        }
                    }
                });
    }


}
